package com.example.mytips.utils;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;

// Messages.showInfoMessage(project, "No text selected.", "No Selection");

public class Mye {

    // 工程
    public Project project;

    // 上下文
    public DataContext context;

    // 编辑器
    public Editor editor;

    // 文档
    public Document document;

    // 当前文件
    public PsiFile psiFile;

    // 当前文件路径
    public String psiFilePath;

    // 光标位置
    public int offset;

    // 选中的文本
    public String selectedText;

    public static Mye builder(AnActionEvent e) {
        Mye mye = new Mye();

        mye.project = e.getProject();
        mye.context = e.getDataContext();
        mye.editor = CommonDataKeys.EDITOR.getData(mye.context);
        mye.document = mye.editor.getDocument();
        mye.offset = mye.editor.getCaretModel().getOffset();
        mye.psiFile = CommonDataKeys.PSI_FILE.getData(mye.context);
        mye.psiFilePath = mye.psiFile.getVirtualFile().getPath();
        mye.selectedText = mye.editor.getSelectionModel().getSelectedText();

        return mye;
    }
}
